package com.ruoyi.web.controller.modules;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.sdstc.modules.eneity.OrgDistributeParamVo;
import com.sdstc.modules.eneity.OrgEntity;
import com.sdstc.modules.query.AdjustQuery;
import com.sdstc.modules.query.ExportCustomQuery;
import com.sdstc.modules.service.OrgService;
import com.sdstc.modules.vo.OrgTreeVo;
import com.sdstc.modules.vo.SelectRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ：wk
 * @date ：Created in 2022/10/21 11:53
 */
@RestController
@RequestMapping("/org")
public class OrgController extends BaseController {

    @Autowired
    private OrgService orgService;

    @PostMapping("/getAdjustAfter")
    public AjaxResult getAdjustAfter(@RequestBody AdjustQuery adjustQuery){
        return AjaxResult.success(orgService.getAdjustAfter(adjustQuery));
    }

    @PostMapping()
    public AjaxResult saveOrg(@RequestBody OrgEntity orgEntity){
        return AjaxResult.success(orgService.saveOrg(orgEntity));
    }

    @PutMapping("/{id}")
    public AjaxResult updateOrg(@PathVariable String id,@RequestBody OrgEntity orgEntity){
        return AjaxResult.success(orgService.updateOrg(orgEntity));
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteOrgById(@PathVariable String id){
        orgService.deleteOrgById(id);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    public AjaxResult listOrg(String orgId){
        return AjaxResult.success(orgService.getOrgSimpleTree(orgId));
    }


    @GetMapping("/getOrgChartList")
    public AjaxResult getOrgChartList(String orgId){
        return AjaxResult.success(orgService.getOrgChartList(orgId));
    }


    @GetMapping("/listSelect")
    public AjaxResult listOrgSelect(String orgId){
        return AjaxResult.success(orgService.getOrgSimpleTreeSelect(orgId));
    }

    @GetMapping("/getList")
    public List<OrgTreeVo> getList(String orgId){
        return orgService.getOrgTree(orgId);
    }

    @GetMapping("/listTreeSelect")
    public AjaxResult listTreeSelect(String orgId){
        return AjaxResult.success(orgService.getOrgTreeSelectVo(orgId));
    }

    @GetMapping("/getSameLevelOrg/{orgId}")
    public AjaxResult getSameLevelOrg(@PathVariable String orgId) {
        return AjaxResult.success(orgService.getSameLevelOrg(orgId));
    }

    //架构调整页面初始查询接口
    @GetMapping("/queryOrgDetail")
    public AjaxResult queryOrgDetail(String orgId){
        return AjaxResult.success(orgService.queryOrgDetail(orgId));
    }

    @GetMapping("/getOrgDetailView")
    public AjaxResult getOrgDetailView(String orgId){
        return AjaxResult.success(orgService.getOrgDetailView(orgId));
    }

    //架构调整页面机构详情接口
    @GetMapping("/queryDetail")
    public AjaxResult queryDetail(String orgId,String officeId,String departmentId,String tempVersionId){
        return AjaxResult.success(orgService.queryDetail(orgId,officeId,departmentId,tempVersionId));
    }
    //架构调整页面调度二级单位数据查询
    @GetMapping("/queryOrg")
    public AjaxResult queryOrg(String orgId,String orgName){
        return AjaxResult.success(orgService.queryOrg(orgId,orgName));
    }
    //架构调整页面调度处级单位数据查询
    @GetMapping("/queryOfficeOrg")
    public AjaxResult queryOfficeOrg(String orgId,String orgName){
        return AjaxResult.success(orgService.queryOfficeOrg(orgId,orgName));
    }

    //架构调整页面机构人员详情接口
    @GetMapping("/queryOrgPeopleDetail")
    public AjaxResult queryOrgPeopleDetail(String orgId,String officeId,String departmentId,String tempId){
        return AjaxResult.success(orgService.queryOrgPeopleDetail(orgId,officeId,departmentId,tempId));
    }

    //机构统计图编制柱状图数据接口
    @GetMapping("/queryBarEchartsData")
    public AjaxResult queryBarEchartsData(String orgId){
        return AjaxResult.success(orgService.queryBarEchartsData(orgId));
    }

    //机构统计图编制柱状图导出excel
    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response, @RequestParam String orgId){
        orgService.exportExcel(response,orgId);
    }

    //机构统计图实配人员柱状图导出excel
    @PostMapping("/exportPersonExcel")
    public void exportPersonExcel(HttpServletResponse response, @RequestParam String orgId){
        orgService.exportPersonExcel(response,orgId);
    }

    //预设编制人员设置分配
    @PostMapping("/orgDistribute")
    public AjaxResult orgDistribute(@RequestBody List<OrgDistributeParamVo> list){
        orgService.orgDistribute(list);
        return AjaxResult.success();
    }



    //机构年度预设编制折线图导出excel
    @PostMapping("/exportYearExcel")
    public void exportYearExcel(HttpServletResponse response, @RequestParam String orgId){
        orgService.exportYearExcel(response,orgId);
    }

    //机构年度实配人数折线图导出excel
    @PostMapping("/exportPersonYearExcel")
    public void exportPersonYearExcel(HttpServletResponse response, @RequestParam String orgId){
        orgService.exportPersonYearExcel(response,orgId);
    }

    @PostMapping("/selectRule")
    public AjaxResult selectRule(@RequestBody SelectRuleVo selectRuleVo){
        return AjaxResult.success(orgService.selectRule(selectRuleVo));
    }

    /**
    *@author: wk
    *@date: 2023/4/10 10:01
    *@description: 自定义导出内容
    */
    @PostMapping("/exportCustom")
    public void exportCustom(HttpServletResponse response, ExportCustomQuery exportCustomQuery){
        orgService.exportCustom(response, exportCustomQuery);
    }

}
